package com.miplus.ccrm.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.miplus.ccrm.admin.controller.vo.AudLogReqVo;
import com.miplus.ccrm.admin.controller.vo.AudLogResVo;
import com.miplus.ccrm.admin.pojo.SysAuditLog;
import com.miplus.ccrm.admin.service.SysAuditLogService;
import com.miplus.ccrm.admin.mapper.SysAuditLogMapper;
import com.miplus.ccrm.common.JPubUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author pc
* @description 针对表【sys_audit_log】的数据库操作Service实现
* @createDate 2024-03-07 10:34:19
*/
@Service
public class SysAuditLogServiceImpl extends MPJBaseServiceImpl<SysAuditLogMapper, SysAuditLog>
    implements SysAuditLogService{

    @Override
    public IPage<AudLogResVo> auditLog(AudLogReqVo paras)
    {
        return selectJoinListPage(new Page<>(paras.getPageNum(), paras.getPageSize()),
                AudLogResVo.class,
                new MPJLambdaWrapper<SysAuditLog>()
                        .selectAs("(select dsc from sys_names n where n.tid='AUDIT.ACTION' and n.id=t.action)",SysAuditLog::getAction)
                        .selectAll(SysAuditLog.class)
                        .between(JPubUtils.IsNotEmpty(paras.getStartdt()),SysAuditLog::getCrdt,JPubUtils.StringToDate(paras.getStartdt()),JPubUtils.StringToDate(paras.getEnddt()))
                        .eq(JPubUtils.IsNotEmpty(paras.getOperator()),SysAuditLog::getOperator,paras.getOperator())
                        .eq(JPubUtils.IsNotEmpty(paras.getAction()),SysAuditLog::getAction,paras.getAction())
                        .orderByDesc(SysAuditLog::getCrdt)
                );
    }
}




